package com.jh.base;


import java.util.List;

public class ResultEntity<T> {

    private String msg;
    private T data;
    private List<T> dataList;
    private int status;
    private int count;

    public String getMsg() {
        return msg;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public ResultEntity() {
        setStatus(RepStatusCode.SUCCESS);
    }

    public ResultEntity(T data) {
        setStatus(RepStatusCode.SUCCESS);
        this.data = data;
    }

    public ResultEntity(String msg) {
        this.status = RepStatusCode.SUCCESS.getCode();
        this.msg = msg;
    }

    public ResultEntity(RepStatusCode repStatusCode) {
        setStatus(repStatusCode);
    }

    public ResultEntity(RepStatusCode repStatusCode, String msg) {
        setStatus(repStatusCode);
        this.msg = msg;
    }

    private void setStatus(RepStatusCode repStatusCode) {
        this.status = repStatusCode.getCode();
        this.msg = repStatusCode.getDescription();
    }

    public static ResultEntity success(){
        return new ResultEntity();
    }

    public static ResultEntity fail(){
        return new ResultEntity(RepStatusCode.UNKNOWN_ERROR);
    }

    public static ResultEntity fail(RepStatusCode repStatusCode) {
        return new ResultEntity(repStatusCode);
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}
